<template>
	<view >
		<custom-navigation-bar title="管家管理"></custom-navigation-bar> 
		<view class="top01" > 
			<view class="top02" style="color: white;">
			&nbsp;&nbsp;&nbsp;&nbsp;共{{nums}}条数据
				<view class="top03">
					<image src="/static/ic_home_search@3x.png" class="top04" @click="showModal"></image>
				</view>
			</view>  
		</view> 
		<view class="top05"></view> 
		<view v-if="modalVisible" class="search">
		    <view class="search_1" @click="closeModal"></view>
			<view class="search_box"> 
				<view class="search_tiem">
					<view class="search_lable">名称</view>
					<view class="search_t"><input type="text" v-model="searchDate.name" class="search_input" placeholder="请输入名称"/> </view>
				</view> 
				 
				<view class="search_tiem">
					<view class="search_lable">状态</view>
					<view class="search_t">
						<view v-for="(item,index) in status" :key="index">
							<view class="search_def" v-if="item.id!=searchInitData.status" @click="selectStatus(item)">
								{{item.name}}
							</view>
							<view class="search_se" v-if="item.id==searchInitData.status" @click="selectStatus(item)">
								{{item.name}}
							</view>
						</view>
					</view>
				</view>
			  
				<view class="search_tiem" style="margin-bottom: 20rpx;">
					<view class="reset_btn" @click="reset">重置</view>
					<view class="ok_btn" @click="search">确定</view>
				</view>
		    </view>
		</view>
		<!-- 商户管理 -->
		<view v-if="data.length>0">
			 <view class="list-item" v-for="(item,index) in data" :key="index" @click="detail(item)">
			 	<view class="list-item-content1" style="height: 90rpx;">
			 		<view class="list-item-content-v">
			 			昵称：{{item.name}}&nbsp;&nbsp;手机号：{{item.phone}}
			 			<label class="status_cussess" v-if="item.status==1">正常</label>
			 			<label class="status_fail" v-if="item.status==2">未通过</label>
			 			<label class="status_fail" v-if="item.status==0">待审核</label>
			 		</view>
			 		<view class="list-item-content-v">
			 			所属小区：{{item.communityName}}
			 		</view>
			 	</view>  
			 </view>
			<view class="more" v-if="pageData.more" @click="getMore()">
			     加载更多
			</view>
			<view class="more" v-if="!pageData.more">
			     无更多数据
			</view>
		</view>
		<view class="more" v-if="data.length==0">
		     暂无数据
		</view>
	
		
		<view style="width: 100%;height: 60rpx;float: left;"></view>
	</view>
</template>

<script setup>
	import CustomNavigationBar from '@/components/CustomNavigationBar.vue'; 
	import { ref } from "vue"; 
	import http from '../../../utils/http';
	function detail(item){
		uni.navigateTo({
			url:"/pages/my/partner/butler_detail?butlerId="+item.id+"&id="+id.value
		})
	}
	const modalVisible=ref(false); 
	function showModal() {
	    modalVisible.value = true;
	}
	function closeModal() {
	    modalVisible.value = false;
	}
	const searchInitData=ref({});
	const searchDate=ref({});
	const status=ref([
		{id:null,name:'全部'},
		{id:0,name:'待审核'},
		{id:1,name:'正常'},
		{id:2,name:'未通过'}
	]);
	 
	function selectStatus(item){
		searchInitData.value.status=item.id;
		searchDate.value.status=item.id;
	}
	function search(){
		closeModal();
		console.log(searchDate.value);
		pageData.value.pageIndex=1;
		initData();
	}
	function reset(){
		searchDate.value={} 
		searchInitData.value={}
		console.log(searchDate.value) 
	}
	  
	const id=ref(0);
	const userId=ref();
	import {
		onLoad,
		onPageScroll
	} from '@dcloudio/uni-app';
	onLoad((query) => {
		id.value=query.id;
		userId.value=getApp().globalData.user.userId
		// id.value=4;
		// userId.value=24;
		initData();
		module();
	})
	//初始化模块
	const moduleArr=ref([
		{
			id:null,
			name:'全部'
		}
	]);
	function module(){
		http.request({
			url: "/sys/menu/list",
			method: "POST",
			data: {
				"pid": 0,
				isShow:1
			}
		}).then((responseData) => { 
			 if(responseData.code==1){
				 //moduleArr.value=responseData.data;
				 for(var i=0;i<responseData.data.length;i++){
					 moduleArr.value.push(responseData.data[i])
				 }
			 }
		}).catch((err) => {
			uni.showToast({
				icon: 'error',
				title: '请求失败'
			})
		})
	}
	function selectModule(item){
		searchInitData.value.module=item.id;
		searchDate.value.module=item.id;
	}
	//----查询开始----
	const data=ref([]); 
	const pageData=ref(
		{
			pageIndex:1,
			pageSize:10,
			more:true
		}
	);
	function getMore(){
		pageData.value.pageIndex=pageData.value.pageIndex+1;
		initData();
	}
	const nums=ref(0);
	function initData(){
		uni.showLoading({
			title: '数据加载中',
			mask:true
		}); 
		http.request({
		 	url: "/x/partner/butler/list",
		 	method: "POST",
		 	data: {
		 		"id":id.value,
				userId:userId.value,
				pageIndex:pageData.value.pageIndex,
				pageSize:pageData.value.pageSize,
				butler:searchDate.value
		 	}
		}).then((responseData) => { 
			uni.hideLoading();
			if(responseData.code==1){
				nums.value=responseData.data.num;
				if(pageData.value.pageIndex==1){
					data.value=responseData.data.list;
				}else{
					if(responseData.data.list.length==0){
						pageData.value.more=false;
					}else{
						for(var i=0;i<responseData.data.list.length;i++){
							data.value.push(responseData.data.list[i])
						} 
					}
				}
			}else if(responseData.code==0){
				uni.showToast({
					icon: 'error',
					title: responseData.message
				})
			}else if(responseData.code==-1){
				uni.navigateTo({
					url: "/pages/login/login"
				});
			}
		}).catch((err) => {
			uni.hideLoading();
		 	uni.showToast({
		 		icon: 'error',
		 		title: '请求失败'
		 	})
		})
	}
	function pageIn(butler){
		//pageData.value.pageIndex=1;
		for(var i=0;i<data.value.length;i++){
			if(butler.id==data.value[i].id){
				data.value[i].status=butler.status
			}
		}
		 
	}
	defineExpose({
		pageIn
	}) 
	 
</script>

<style>
	@import "../../list/list.scss";
	@import "../../login/xieyi.scss";
	 .xiaoqu_item{
		 width: 90%;float: left;margin-left: 5%;background: white;margin-top: 20rpx;height: 80rpx;line-height: 80rpx;border-radius: 20rpx;
	 }
	 .more{
		 width: 100%;text-align: center;line-height: 50rpx;color: #666666;font-size: 25rpx;float: left;margin-top: 10rpx;
	 }
	 .edit{
		 float: right;color: dodgerblue;margin-right: 50rpx;
	 }
</style>